const { defineConfig } = require("@vue/cli-service");

module.exports = defineConfig({
  transpileDependencies: true,

  // WebAssembly 支持
  configureWebpack: {
    experiments: {
      asyncWebAssembly: true,
    },
    module: {
      rules: [
        {
          test: /\.wasm$/,
          type: "javascript/auto",
          loader: "wasm-loader",
        },
      ],
    },
  },

  // 构建优化
  chainWebpack: (config) => {
    // 删除预加载
    config.plugins.delete("preload");
    config.plugins.delete("prefetch");

    // 压缩代码
    config.optimization.minimize(true);

    // 优化打包分割
    config.optimization.splitChunks({
      chunks: "all",
      cacheGroups: {
        vendor: {
          name: "chunk-vendors",
          test: /[\\/]node_modules[\\/]/,
          priority: 10,
          chunks: "initial",
        },
        elementUI: {
          name: "chunk-elementUI",
          priority: 20,
          test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
        },
        commons: {
          name: "chunk-commons",
          minChunks: 3,
          priority: 5,
          chunks: "initial",
          reuseExistingChunk: true,
        },
      },
    });
  },

  // 生产环境关闭 source map
  productionSourceMap: false,
});
